<template>
	<view>
		<view class="list-public2">
			<view class="flex-start top-hint">
				<text>不知道怎么写，试一试这个吧</text>
				<view class="flex-align-center view-template" @click="viewInstances()">
					<image class="imageRadom " :src="radomPath"></image>
					<view>查看范本</view>
				</view>
			</view>

			<!-- <view class="flex-columns padding-bottom_30rpx">
				<view class="margin-bottom_20rpx flex-align-center">
					<view class="icon-cls"></view>
					<view class="font-size_32rpx color333">项目名称</view>
					<span class="must">*</span>
				</view>
				<input type="text" v-model="form.entryName" class="input-frame" placeholder="请输入项目名称" placeholder-class="placeholder" />
			</view> -->

			<!-- 生产工厂 -->
			<block>




				<view class="flex-columns padding-bottom_30rpx">
					<view class="margin-bottom_20rpx flex-align-center">
						<view class="icon-cls"></view>
						<view class="font-size_32rpx color333">标题主题</view>
						<span class="must">*</span>
					</view>
					<view class="textarea-box">
						<textarea placeholder-style="font-size:30rpx;" v-model="form.name"
							placeholder="请输入你的产品和服务（可以输入多个用逗号隔开）" maxlength="500" style="height: 200rpx;" />
					</view>
				</view>
				<view class="flex-columns padding-bottom_30rpx">
					<view class="margin-bottom_20rpx flex-align-center">
						<view class="icon-cls"></view>
						<view class="font-size_32rpx color333">标题附加</view>
						<span class="must">*</span>
					</view>
					<view class="textarea-box">
						<textarea placeholder-style="font-size:30rpx;" v-model="form.content"
							placeholder="用一句话描述你的产品服务与特色" maxlength="500" style="height: 200rpx;" />
					</view>
				</view>

				<view class="flex-columns padding-bottom_30rpx">
					<view class="margin-bottom_20rpx flex-align-center ">
						<view class="icon-cls"></view>
						<view class="font-size_32rpx color333">生成条数</view>
						<span class="must">*</span>
					</view>
					<input type="number" v-model="form.rows" class="input-frame" @input="inputGo(form.rows)" placeholder="请输入生成条数"
						placeholder-class="placeholder" />
				</view>

			</block>





			<view class="" style="height: 200rpx;">

			</view>

			<view class="c-but flex" @click="but()">立即生成 {{'('+"算力："+numberTotal+')'}}</view>
		</view>

	</view>
</template>

<script>
	import radomList from './textList.js'
	export default {
		data() {
			return {
				radomPath: '',

				textList: radomList.textList,
				form: {
					name: '',
					content: '',
					rows: ''
				},
				tallySet: uni.getStorageSync('tallySet'),
				numberTotal:0,
				user: uni.getStorageSync('user'),
				memberSetObj:{}
				

			};
		},
		onLoad(options) {
			
			this.tallySetFn()
			this.userInfos()
			this.memberSetFn()

		},
		onShow() {
			this.$nextTick(() => {
				this.mescroll?.resetUpScroll();
			})
		},
		methods: {
			inputGo(e){
				console.log(e)
				if(e){
					this.numberTotal=Number(e)*this.tallySet.aicreate_tally
				}else{
					this.numberTotal=0
				}
				
			},
		
			async userInfos() {
				const result = await this.$http.get({
					url: this.$api.userInfo,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 上级id
						// pid: ''
					}
				});
				if (result.errno == 0) {
					this.user = result.data;
			
					uni.setStorageSync('user', result.data);
			
			
				}
			},
			async tallySetFn() {
				const result = await this.$http.get({
					url: this.$api.tallySet,
					
				});
				if (result.errno == 0) {
					console.log(result.data)
					
			      uni.setStorageSync('tallySet', result.data);
				  
				  this.numberTotal=result.data.aicreate_tally
					
			
			
				} else {
					this.$sun.toast(result.message, 'none')
				}
			},
			viewInstances() {

				this.form = {
					name: '便携式吸尘器旗舰店',
					content: '强力吸力、长时间续航、轻巧便捷',
					rows: 1

				}

			},
			async memberSetFn() {
				const result = await this.$http.get({
					url: this.$api.memberSet,
					data: {
			
			
					}
				});
				if (result.errno == 0) {
			
					this.memberSetObj = result.data
			
					console.log(result.data)
			
				}
			},
			async but() {
				
				if (this.user.is_member == 0&&this.memberSetObj.is_open==1) {
					uni.showModal({
						title: '温馨提示',
						content: '你当前不是会员，请开通会员后享受该功能',
						confirmText: '开通会员',
						confirmColor: '#4A5EFF',
						success: async (res) => {
							if (res.confirm) {
				
				
								this.$sun.navGo('/pages/contactUs/memberCenter')
				
							} else if (res.cancel) {
				
							}
						}
					});
				} else {
					if(!this.form.name){
						this.$sun.toast('请输入标题主题','none')
						return
					}
					
					if(!this.form.content){
						this.$sun.toast('请输入标题附加','none')
						return
					}
					if(!this.form.rows){
						this.$sun.toast('请输入生成条数','none')
						return
					}
					
					uni.showLoading({
						title: '生成中...',
						mask: true
					});
					const result = await this.$http.get({
						url: this.$api.aicreateSave,
						data: {
							uid: uni.getStorageSync('uid'),
							name: this.form.name,
							content: this.form.content,
							rows: this.form.rows,
					
						}
					});
					if (result.errno == 0) {
						console.log(result.data)
						
						uni.hideLoading()
						
						setTimeout(()=>{
							this.$sun.toast(result.message, 'none')
							this.$sun.navBack()
						},200)
					
					} else {
						uni.hideLoading()
						setTimeout(()=>{
							this.$sun.toast(result.message, 'none')
						},200)
						
					}
				}
				
				

				// this.$sun.navGo('/pagesA/creatCenter/keywordCreation/keywordStepOne')
			},
			delFn() {
				uni.showModal({
					title: '是否确定要删除',
					content: '是否要删除该文件夹，如果删除，将不可恢复，请您谨慎选择',
					success: async (res) => {
						if (res.confirm) {


						} else if (res.cancel) {

						}
					}
				});
			},
		}
	};
</script>

<style lang="less">
	.library {
		// width: 210rpx;
		text-align: center;
		padding: 14rpx;
		border-radius: 10rpx;
		background-color: #fafafc;
		color: #000;
		margin-right: 40rpx;
	}

	.c-but {

		font-weight: 700;

		padding: 20rpx 40rpx;

		// color: #ffffff;
		width: 90%;
		position: fixed;
		bottom: 40rpx;
		left: 3%;
		border: none;

		z-index: 999;


		border-radius: 112rpx;
		margin: 20rpx;
		text-align: center;
		font-size: 32rpx;
		height: 100rpx;
		margin-top: 30rpx;
		color: #ffffff;
		background: linear-gradient(90deg, #6475FF, #7464FF 100%);
	}

	.library2 {
		// width: 210rpx;
		text-align: center;
		padding: 14rpx;
		border-radius: 10rpx;
		background-color: #fafafc;
		color: #000;
		margin-right: 40rpx;
	}

	page {
		background-color: #fff;
	}

	.uni-textarea-placeholder {
		color: #c9caca;
		overflow: hidden;
	}

	// 多行文本
	.textarea-box {
		// width: 630rpx;
		border-radius: 20rpx;
		background: rgb(243, 243, 244);
		padding: 24rpx;
		margin: 0rpx 0 42rpx;

		.textarea-color {
			color: #999;
		}
	}

	.suspension {
		position: fixed;
		right: 20rpx;
		width: 80rpx;
		bottom: 500rpx;
		height: 80rpx;
		border-radius: 50%;
		background-color: #fff;
		text-align: center;
		line-height: 100rpx;
		z-index: 999;
		filter: drop-shadow(0rpx 4rpx 12rpx rgba(0, 0, 0, 0.15));

		.addIcon {
			width: 40rpx;
			height: 40rpx;
		}
	}

	.icon {
		width: 36rpx;
		height: 36rpx;
	}

	.list-public2 {
		background-color: #fff;
		padding: 40rpx 30rpx 0;

	}

	.imageRadom {
		width: 34rpx !important;
		height: 34rpx !important;
	}

	.top-hint {
		margin-bottom: 46rpx;

		text {
			color: rgb(198, 198, 198);
		}

		.view-template {
			image {
				width: 42rpx;
				height: 34rpx;
				margin: 0 10rpx 0 20rpx;
			}

			view {
				color: rgb(0, 193, 255);
			}
		}
	}

	.icon-cls {
		margin-right: 10rpx;
		width: 12rpx;
		height: 32rpx;
		border-radius: 98rpx;
		background: linear-gradient(180deg, rgb(109, 221, 245), rgb(66, 72, 244) 100%);
	}

	.must {
		color: red;
		margin-left: 8rpx;
	}

	.input-frame {
		// width: 384rpx;
		width: 650rpx;
		border-radius: 20rpx;
		background: rgb(243, 243, 244);
		padding: 24rpx;
		margin: 0rpx 0 42rpx;
	}

	.input-frame2 {
		width: calc(100% - 76rpx);
		border-radius: 20rpx;
		background: rgb(243, 243, 244);
		padding: 24rpx;
		margin: 0rpx 0 42rpx;
	}

	.input-frame3 {
		width: calc(100% - 76rpx);
		border-radius: 20rpx;
		background: rgb(243, 243, 244);
		padding: 24rpx;
		margin: 0rpx 0 42rpx;
	}

	.fixed-btn {
		z-index: 5;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background-color: #fff;
		height: 200rpx;
	}

	.but {
		margin: 30rpx 0;
		border-radius: 116rpx;
		box-shadow: 4rpx 6rpx 28rpx 0rpx rgba(30, 156, 214, 0.81), inset 0rpx 0rpx 22rpx 0rpx rgba(204, 235, 255, 0.3);
		background: linear-gradient(90deg, rgb(105, 229, 253), rgb(68, 65, 253) 100%);
		width: 428rpx;
		height: 87rpx;
		text-align: center;
		padding: 20rpx;
		color: #ffffff;
		font-size: 32rpx;
	}
</style>